

import 'package:package_info/package_info.dart';

import 'MyEntityLog.dart';

/**
 * 更新实体
 */

class UpdateEntity {
  String? id;
  String? name;
  String? device;
  String? packagesize;
  String? version;
  String? update;
  String? popup;
  String? downloadurl;
  String? ipaurl;
  String? plisturl;
  String? content;
  Config? config;

  UpdateEntity({
    this.id,
    this.name,
    this.device,
    this.packagesize,
    this.version,
    this.update,
    this.popup,
    this.downloadurl,
    this.ipaurl,
    this.plisturl,
    this.content,
    this.config,
  });

  /**
   * 是否有新版本
   */
  Future<bool> haveUpdate() async {
    PackageInfo info = await PackageInfo.fromPlatform();
    if (version!.compareTo(info.version) == 1) {
      return true;
    }
    return false;
  }

  UpdateEntity.fromJson(Map<String, dynamic> json) {
    id = MyEntityLog.handleString(json, 'id');
    name = MyEntityLog.handleString(json, 'name');
    device = MyEntityLog.handleString(json, 'device');
    packagesize = MyEntityLog.handleString(json, 'packagesize');
    version = MyEntityLog.handleString(json, 'version');
    update = MyEntityLog.handleString(json, 'update');
    popup = MyEntityLog.handleString(json, 'popup');
    downloadurl = MyEntityLog.handleString(json, 'downloadurl');
    ipaurl = MyEntityLog.handleString(json, 'ipaurl');
    plisturl = MyEntityLog.handleString(json, 'plisturl');
    content = MyEntityLog.handleString(json, 'content');
    if (json.containsKey('config')) {
      var tmp = json['config'];
      if (tmp is Map) {
        config =
            json['config'] != null ? new Config.fromJson(json['config']) : null;
      } else {
        config = null;
      }
    } else {
      config = null;
    }
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['device'] = this.device;
    data['packagesize'] = this.packagesize;
    data['version'] = this.version;
    data['update'] = this.update;
    data['popup'] = this.popup;
    data['downloadurl'] = this.downloadurl;
    data['ipaurl'] = this.ipaurl;
    data['plisturl'] = this.plisturl;
    data['content'] = this.content;
    if (this.config != null) {
      data['config'] = this.config!.toJson();
    }
    return data;
  }
}

class Config {
  String? bata_control;

  Config({
    this.bata_control,
  });

  Config.fromJson(Map<String, dynamic> json) {
    bata_control = MyEntityLog.handleString(json, 'bata_control');
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['bata_control'] = this.bata_control;
    return data;
  }
}
